package Models

import (
	"fmt"
	Mysql "gin/study_1/Databases"
	"github.com/jinzhu/gorm"
)

type Student struct {
	Id     int    `gorm:"primary_key" json:"id"`
	Name   string `gorm:"column:name"  json:"name"`
	Age    string `gorm:"column:age" json:"age"`
	Sex    bool   `gorm:"column:sex" json:"sex"`
	Number int    `gorm:"column:number" json:"number"`
	gorm.Model
}

func init() {
	fmt.Println("初始化Student")
	Mysql.DB.AutoMigrate(&Student{})
}

// 插入一条数据 并返回返回值
func (this *Student) Insert()(id int,err error)  {
	result := Mysql.DB.Create(&this)
	id = this.Id
	if result.Error != nil{
		err = result.Error
		return
	}
	return
}


// 查询出所有的 Student信息
func (this *Student) SelectAll()(AllStudent []Student){
		Mysql.DB.Find(&AllStudent)
		return
}

